from utils import ArgumentParser, ConfigLoader, LOG
from model import GLMModel, OpenAIModel
from translator import PDFTranslator

if __name__ == "__main__":
    # 解析命令行参数
    argument_parser = ArgumentParser()
    args = argument_parser.parse_arguments()

    # 加载配置文件
    config_loader = ConfigLoader(args.config)
    config = config_loader.load_config()

    # 获取模型名称和 API 密钥
    model_name = args.openai_model if args.openai_model else config['OpenAIModel']['model']
    api_key = args.openai_api_key if args.openai_api_key else config['OpenAIModel']['api_key']

    # 实例化 OpenAIModel 类
    model = OpenAIModel(model=model_name, api_key=api_key)

    # 获取 PDF 文件路径和文件格式
    pdf_file_path = args.book if args.book else config['common']['book']
    file_format = args.file_format if args.file_format else config['common']['file_format']

    # 实例化 PDFTranslator 类，并调用 translate_pdf() 方法进行翻译
    translator = PDFTranslator(model)
    translator.translate_pdf(pdf_file_path, file_format)
